const state = {
  cachedViews: []
}

const mutations = {
  ADD_CACHED_VIEW: (state, view) => {
    if (!state.cachedViews.includes(view)) {
      state.cachedViews.push(view)
    }
  },
  DEL_CACHED_VIEW: (state, view) => {
    const index = state.cachedViews.indexOf(view)
    if (index > -1) {
      state.cachedViews.splice(index, 1)
    }
  }
}

const actions = {
  addCachedView({ commit }, view) {
    commit('ADD_CACHED_VIEW', view)
  },
  delCachedView({ commit }, view) {
    commit('DEL_CACHED_VIEW', view)
  }
}

export default {
  namespaced: true, // 必须设置 namespaced: true
  state,
  mutations,
  actions
}